package com.itheima.day18.xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class XmlParse {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(new File("day 18XML&DTD&schma&,枚举类型\\xml\\stu.xml"));
        Element root = doc.getRootElement();
        List<Element> elements = root.elements();
        ArrayList<Student> list = new ArrayList<>();
        for (Element element : elements) {
            Attribute attribute = element.attribute("id");
            String id = attribute.getValue();
            Element name = element.element("name");
            String text1 = name.getText();
            Element age = element.element("age");
            String text2 = age.getText();
            Student stu=new Student(id,text1,Integer.parseInt(text2));
            System.out.println(stu.toString());
        }

    }
}
